package cn.neusoft.mapper;

import cn.neusoft.pojo.User;
import cn.neusoft.query.BaseQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User>{


    @Insert({"<script>",
            "insert into t_user(password, username, realname, gender, phone, userImg, delTag)",
            "        values(#{password}," ,
            "               #{username}," ,
            "               #{realname}," ,
            "               #{gender}," ,
            "               #{phone}," ,
            "               #{userImg}," ,
            "               #{delTag})" ,
            "</script>"})
    int add(User user);

    @Update({"<script>",
            "update t_user set" ,
            "password=#{password}," ,
            "username=#{username}," ,
            "realname=#{realname}," ,
            "gender=#{gender}," ,
            "phone=#{phone}," ,
            "userImg=#{userImg}," ,
            "delTag=#{delTag}," ,
            "where userId=#{userId}",
            "</script>"})
    int update(User user);

    @Delete("delete from t_user where userId=#{userId}")
    int delete(Integer id);

    @Select("select userId, password, username, realname, gender, phone, userImg, delTag\n" +
            "from t_user where userId=#{userId}")
    User getById(Integer id);

    @Select({"<script>",
            "select userId, password, username, realname, gender, phone, userImg, delTag",
            "from t_user" ,
            " order by userId desc",
            "</script>"})
    List<User> getAll();
}
